/**
 * 详情对话框
 */
var BannerInfoDlg = {
    data: {
        id: "",
        name: "",
        img: "",
        url: "",
        createUser: "",
        createTime: "",
        updateTime: ""
    }
};

layui.use(['form', 'admin', 'ax','laydate','upload','formSelects'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var upload = layui.upload;


    upload.render({
        elem: '#zhinanBtn',
        url: Feng.ctxPath + '/upload/upload',
        before: function (obj) {
            var index = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            setTimeout(function () {
                obj.preview(function (index, file, result) {
                    $("#uploadZN").html(file.name);
                });
            }, 100)
        },
        done: function (res) {
            setTimeout(function () {
                $("#img").val(res.url);
                $("#imgUrl").attr("src",res.url);
                layer.closeAll();
                Feng.success(res.msg);
            }, 100)
        }, error: function () {
            Feng.error("上传失败！");
        }
    });

    var ajax = new $ax(Feng.ctxPath + "/banner/detail?id=" + Feng.getUrlParam("id"));
    var result = ajax.start();
    /*form.val('merchantForm', result.data);*/
    $("#imgUrl").attr("src", result.data.img);






    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/banner/detail?id=" + Feng.getUrlParam("id"));
    var result = ajax.start();
    form.val('bannerForm', result.data);

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/banner/editItem", function (data) {
            Feng.success("更新成功！");
            window.location.href = Feng.ctxPath + '/banner'
        }, function (data) {
            Feng.error("更新失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

    $('#cancel').click(function(){
        window.location.href = Feng.ctxPath + '/banner'
    });
});